load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin
  model  = (/"ACCESS-ESM1-5","MIROC6"/) 
  int    = new((/2,150/),float)

  do m=0,1
    fread = addfile("data/pr_timeseries_1951-2020_JJAS_historical_"+model(m)+".nc","r")
    preh  = fread->prN; averaged precipitation over northern HMA

    fread = addfile("data/pr_timeseries_2021-2100_JJAS_ssp245_"+model(m)+".nc","r")
    pres  = fread->prN

    n  = dimsizes(preh)
    pr = new((/n(0),150/),"float")

    pr(:,:69) = preh 
    pr(:,70:) = pres

    pr        = pr-conform(pr,dim_avg_n_Wrap(pr,0),1);  the departure from the ensemble mean for each member
    pr        = runave_n_Wrap(pr,9,0,1)
    int(m,:)  = dim_stddev_n_Wrap(pr,0)

    delete([/pr,preh,pres/])
  end do 

  noise = dim_avg_n_Wrap(int,0);noise under SSP2-4.5 scenario

end 
